package stores

import (
	"jvm/instructions/base"
	"jvm/rtda"
)

// DSTORE Store double into local variable
type DSTORE struct{ base.Index8Instruction }

func (ds *DSTORE) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, ds.Index)
}

type DSTORE_0 struct{ base.NoOperandsInstruction }

func (ds *DSTORE_0) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, 0)
}

type DSTORE_1 struct{ base.NoOperandsInstruction }

func (ds *DSTORE_1) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, 1)
}

type DSTORE_2 struct{ base.NoOperandsInstruction }

func (ds *DSTORE_2) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, 2)
}

type DSTORE_3 struct{ base.NoOperandsInstruction }

func (ds *DSTORE_3) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, 3)
}

func _dstore(jFrame *rtda.JFrame, index uint) {
	val := jFrame.OperandStack().PopDouble()
	jFrame.LocalVars().SetDouble(index, val)
}
